﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CourseSystem.Common;
using CourseSystem.Common.Helpers;
using CourseSystem.Core.BLL;
using CourseSystem.Core.Entities;

namespace CourseSystem.Web.Controllers
{
    public class AdminSupportController : BaseController
    {
        //
        // GET: /AdminSupport/

        [UploadAuth]
        public ActionResult Guide()
        {
            var info = CourseSettingBLL.GetFromDb();
            if (info == null)
                return NotFound();
            return View(info);
        }

        [HttpPost]
        [ValidateInput(false)]
        [UploadedAuth]
        public ActionResult Guide(CourseSettingInfo info)
        {
            var oldInfo = CourseSettingBLL.GetFromDb();
            oldInfo.CourseGuide = info.CourseGuide ?? "";
            if (CourseSettingBLL.Edit(oldInfo))
            {
                SetAlertMsg("编辑成功.");
                return View(oldInfo);
            }
            SetAlertMsg("未知错误.");
            return View();
        }
        [UploadAuth]
        public ActionResult Helper()
        {
            var info = CourseSettingBLL.GetFromDb();
            if (info == null)
                return NotFound();
            return View(info);
        }

        [HttpPost]
        [ValidateInput(false)]
        [UploadedAuth]
        public ActionResult Helper(CourseSettingInfo info)
        {
            var oldInfo = CourseSettingBLL.GetFromDb();
            oldInfo.CourseHelper = info.CourseHelper ?? "";
            if (CourseSettingBLL.Edit(oldInfo))
            {
                SetAlertMsg("编辑成功.");
                return View(oldInfo);
            }
            SetAlertMsg("未知错误.");
            return View();
        }

    }
}
